import 'package:flutter/material.dart';
import 'dart:math' as math;

class Exam_18 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("变换（Transform）"),
      ),
      body: Content(),
    );
  }
}

class Content extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[
        Transform1(),
        Line(),
        Transform2(),
        Line(),
        Transform3(),
        Line(),
        Transform4(),
      ],
    );
  }
}

/**分割线*/
class Line extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return SizedBox(
      width: double.infinity,
      height: 2,
      child: Container(
        color: Colors.grey[200],
      ),
    );
  }
}

class Transform1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      color: Colors.black,
      margin: EdgeInsets.only(top: 50, left: 30, bottom: 16),
      child: Transform(
        alignment: Alignment.topRight,
        transform: Matrix4.skewY(0.5),
        child: Container(
          padding: const EdgeInsets.all(8.0),
          color: Colors.deepOrange,
          child: const Text("2020新年好"),
        ),
      ), //沿
      // y轴倾斜0.3弧度
    );
  }
}

/**平移*/
class Transform2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(top: 50, left: 30, bottom: 16),
      child: DecoratedBox(
        decoration: BoxDecoration(color: Colors.red),
        //默认原点是左上角，
        child: Transform.translate(
          offset: Offset(-20.0, -5.0),
          child: Text("Hello"),
        ),
      ),
    );
  }
}

/**旋转*/
class Transform3 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(top: 50, left: 30, bottom: 16),
      child: DecoratedBox(
        decoration: BoxDecoration(color: Colors.red),
        child: Transform.rotate(
          angle: math.pi / 2, //旋转90度
          child: Text("AAAA"),
        ),
      ),
    );
  }
}

/**缩放*/
class Transform4 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      margin: EdgeInsets.only(top: 50, left: 30, bottom: 16),
      child: DecoratedBox(
        decoration: BoxDecoration(color: Colors.red),
        child: Transform.scale(
          scale: 1.5, //放大到1.5倍
          child: Text("Flutter"),
        ),
      ),
    );
  }
}
